package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaDiscountInformationDao;
import com.example.informationEntry.entity.NaDiscountInformation;
import com.example.informationEntry.service.NaDiscountInformationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 优惠信息表(NaDiscountInformation)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naDiscountInformationService")
public class NaDiscountInformationServiceImpl implements NaDiscountInformationService {
    @Resource
    private NaDiscountInformationDao naDiscountInformationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param discountInfNumber 主键
     * @return 实例对象
     */
    @Override
    public NaDiscountInformation queryById(String discountInfNumber) {
        return this.naDiscountInformationDao.queryById(discountInfNumber);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<NaDiscountInformation> queryAllByLimit(int offset, int limit) {
        return this.naDiscountInformationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 查询多条数据
     *
     * @param naDiscountInformation 实例对象
     * @return list集合
     */
    @Override
    public List<NaDiscountInformation> queryAll(NaDiscountInformation naDiscountInformation) {
        return this.naDiscountInformationDao.queryAll(naDiscountInformation);
    }

    /**
     * 新增数据
     *
     * @param naDiscountInformation 实例对象
     * @return 实例对象
     */
    @Override
    public NaDiscountInformation insert(NaDiscountInformation naDiscountInformation) {
        this.naDiscountInformationDao.insert(naDiscountInformation);
        return naDiscountInformation;
    }

    /**
     * 修改数据
     *
     * @param naDiscountInformation 实例对象
     * @return 实例对象
     */
    @Override
    public NaDiscountInformation update(NaDiscountInformation naDiscountInformation) {
        this.naDiscountInformationDao.update(naDiscountInformation);
        return this.queryById(naDiscountInformation.getDiscountInfNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param discountInfNumber 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String discountInfNumber) {
        return this.naDiscountInformationDao.deleteById(discountInfNumber) > 0;
    }

    @Override
    public Map<String,Map<String,Object>> queryDiscInf() {
        List<NaDiscountInformation> list = this.naDiscountInformationDao.queryAll(new NaDiscountInformation());
        Map<String,Map<String,Object>> resultMap = new HashMap<>();

        for (NaDiscountInformation naDiscountInformation : list) {
            Map<String,Object> map = new HashMap<>();
            map.put("discountInfName",naDiscountInformation.getDiscountInfName());
            map.put("discountAmount",naDiscountInformation.getDiscountAmount());
            resultMap.put(naDiscountInformation.getDiscountInfNumber(),map);
        }
        return resultMap;
    }
}